<!--
 * @Author: your name
 * @Date: 2020-10-22 17:59:38
 * @LastEditTime: 2021-01-03 19:55:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tlwok-filing-saas-front\src\layouts\LayoutMenu.vue
-->
<template>
  <el-menu
    class="layout-menu"
    :default-active="$route.path"
    :default-openeds="defaultOpeneds"
  >
    <div style="background: #fff">
      <layout-sub-menu :menu-list="menuList" />
    </div>
    <slot></slot>
  </el-menu>
</template>

<script>
import LayoutSubMenu from './LayoutSubMenu'
import Http from '@/lib/http'
export default {
  components: {
    LayoutSubMenu,
  },
  props: {
    menu: Array,
  },
  data() {
    return {
    }
  },
  computed: {
    userInfo () {
      return this.$root.userInfo || null
    },
    defaultMenu () {
      console.log('this.$root.userInfo', this.$root.userInfo.eqshouSupplier, this.$root.userInfo.eqshouSupplier === 0)
      return [
        {
          title: '首页',
          icon: 'el-icon-s-home',
          url: '/customer',
        },
        {
          title: '我的报备',
          icon: 'el-icon-menu',
          url: '/customer/order',
          children: [
            {
              title: '订单报备',
              icon: 'el-icon-s-home',
              url: '/customer/order',
            },
            {
              title: '竞价报备',
              icon: 'el-icon-s-home',
              url: '/customer/bidding',
            },
            {
              title: '商品上架',
              icon: 'el-icon-s-home',
              url: '/customer/goods',
              // disabled: true,
            },
            {
              title: '易企收(提前回款)',
              icon: 'el-icon-s-home',
              url: Http.getUrl('/redirectToEqushou'),
              hide: !this.$root.userInfo || this.$root.userInfo.eqshouSupplier === 0,
            },
          ],
        },
        {
          title: '我的订单',
          icon: 'el-icon-s-home',
          url: 'http://shop.tlwok.com/entrustOrderList/toEntrustOrderList.html',
        },
        {
          title: '分配订单',
          icon: 'el-icon-s-home',
          url: '/customer/factoryOrder',
        },
      ]
    },
    defaultOpeneds() {
      return ['/customer/order']
    },
    menuList() {
      if (this.menu) return this.checkMenuHide(this.menu)
      else {
        const isOfflineRole = this.$store.getters.getOfflineRole
        if (isOfflineRole)
          this.defaultMenu.push({
            title: '线下采购订单',
            icon: 'el-icon-s-order',
            url: '/customer/PO',
          })
        return this.checkMenuHide(this.defaultMenu)
      }
    },
  },
  methods: {
    checkMenuHide (list) {
      return list.filter(item => {
        if (item.children) {
          item.children = this.checkMenuHide(item.children)
        }
        return item.hide !== true
      })
    },
    onClickMenu(menu) {
      if (menu.url.indexOf('http') === 0 || menu.url.indexOf('/api') === 0) {
        window.open(menu.url)
      } else {
        this.$router.push(menu.url)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.layout-menu {
  height: 100%;
  width: 179px;
  overflow: hidden;
}
</style>
